import commrequest from './commonrequest.js'
const baseUrl = "https://community.chuangxiangdianli.com/api/"; //公共路径

// post请求封装
function postRequest({
	url,
	data,
	flag
}) {
	console.log(url,data)
	// loading加载
	var isloading=flag||true
	let promise = new Promise((resolve, reject) => {
		let _this = this;
		let postData = data; 
		commrequest.commrequest({
			isloading,
			url:url,
			data:postData,
			method:'POST',
			callBack:(res)=>{
				resolve(res.data);
				},
			fail:(res)=>{
				reject('err')
			}
		})
		// uni.request({
		// 	url: baseUrl + url,
		// 	data: postData,
		// 	method: "POST",
		// 	header: {
		// 		"content-type": "application/x-www-form-urlencoded",
		// 		"Authorization": 'Bearer' + ' ' + uni.getStorageSync("userInfo").token
		// 	},
		// 	success: function(res) { 
		// 		uni.hideLoading()
		// 		if (res.data.code == 200) {
		// 			resolve(res.data);
		// 		}else if (res.data.code == 500){
		// 			uni.showToast({
		// 				title: res.data.msg,
		// 				icon: 'none'
		// 			}) 
		// 		}else{
		// 			resolve(res.data);
		// 		}
		// 		// 取消loading加载
		// 		uni.hideLoading()
		// 	},
		// 	error: function(e) {
		// 		uni.hideLoading()
		// 		reject("网络出错");
		// 	}
		// });
	});
	return promise;
}

// get请求封装
function getRequest(url, data,flag) { 
	var isloading=flag||true
	let promise = new Promise((resolve, reject) => {
		let _this = this;
		let postData = data;

		commrequest.commrequest({
			isloading,
			url:url,
			data:postData,
			method:'GET',
			callBack:(res)=>{
				resolve(res.data);
},
			fail:(res)=>{
				reject('err')
			}
		})
		// uni.request({
		// 	url: baseUrl + url,
		// 	data: postData,
		// 	method: "GET",
		// 	dataType: "json",
		// 	header: {
		// 		"content-type": "application/json",
		// 		"Authorization": 'Bearer' + ' ' + uni.getStorageSync("userInfo").token
		// 	},
		// 	success: function(res) {
		// 		uni.hideLoading()
		// 		if (res.data.code == 200) {
		// 			resolve(res.data);
		// 		} else {
		// 			// 20001 用户未注册
		// 			if (res.data.code == 20001) {
		// 				uni.showToast({
		// 					title: res.data.msg,
		// 					icon: 'none'
		// 				}) 
		// 				let time = setTimeout(() => {
		// 					uni.navigateTo({
		// 						url: '/login/registerinfo/index',
		// 						success() {
		// 							clearTimeout(time)
		// 						}
		// 					})
		// 				}, 1000)
		// 			}
		// 			resolve(res.data);
		// 		}
		// 		uni.hideLoading()
		// 	},
		// 	error: function(e) {
		// 		uni.hideLoading()
		// 		uni.showToast({
		// 			title: '系统错误',
		// 			icon: 'none'
		// 		})
		// 	}
		// });
	});
	return promise;
}
const falseToken={"openid":"ojnPC4ndJiPo8d3yUu1QeUMd3UJk","unionid":"o88Zs6cffzpiEkGwCM8OWMqh16jA","nickName":"undefined","gender":1,"language":"zh_CN","city":"","province":"","country":"China","avatarUrl":"https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eo4c1cGaWUiaXSd1M7iaw3YqTxzwKO23fgDicapwaDFZUsPAliccticVG5SiahhyHbNgYaSDlgc26LVx95w/132","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvY29tbXVuaXR5LmNodWFuZ3hpYW5nZGlhbmxpLmNvbVwvYXBpXC93ZWNoYXRcL3JlZ2lzdGVyIiwiaWF0IjoxNjE2MzkzMDQ2LCJleHAiOjE2MTY5OTc4NDYsIm5iZiI6MTYxNjM5MzA0NiwianRpIjoiZmFuV0hiT0k0Ym5ObjRUQyIsInN1YiI6ODgsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjcifQ.HNM-hPMxB2kjBvjtEaWjAImnlp0jcatCAy9-gP72i50","userInfo":{"id":88,"username":"undefined","password":"","pay_password":"","nickname":"undefined","sex":1,"avatar":"https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eo4c1cGaWUiaXSd1M7iaw3YqTxzwKO23fgDicapwaDFZUsPAliccticVG5SiahhyHbNgYaSDlgc26LVx95w/132","phone":"17635385962","email":"","money":"0.00","flea_frozen_money":"0.00","frozen_money":"0.00","integral":"0.00","inviter_id":0,"ip":"39.71.46.28","login_time":"2020-07-05 14:16:47","last_login_time":"2020-07-05 14:16:47","created_at":"2021-03-22T06:04:06.000000Z","updated_at":"2021-03-22T06:04:06.000000Z","community_id":1,"room_id":192,"status":1,"property_id":1,"openid":"ojnPC4ndJiPo8d3yUu1QeUMd3UJk","session_key":null,"unionid":null,"user_intro":null,"flea_money":"0.00","province_id":15,"city_id":89,"area_id":1048,"address":"山东省-济南市-历城区","phone_str":"176****5962","community":"玫瑰花园","roomInfo":"1号楼-2单元-1层-102"}}
module.exports = {
	post: postRequest,
	get: getRequest,
	falseToken
};


 